-
Notifications
You must be signed in to change notification settings - Fork 220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid using sets when existing slices suffice #1719
Conversation
} | ||
|
||
// the object might be getting deleted | ||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) | ||
if ok { | ||
if ns, ok := tombstone.Obj.(*corev1.Namespace); ok { | ||
return interestingNamespacesSet.Has(ns.Name) | ||
return slices.Contains(interestingNamespaces, ns.Name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm in favor of using slices.Contains
instead of constructs like:
sets.New(HostnameMatchSpecCandidates(hostname)...).Has(matchSpec)
But I'm not sure about cases like this one, as we're going from O(1) to O(n) and I'm not sure how often these are called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That’s a good point, the checker is used in an informer so slices don’t suffice here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ve restored two uses of sets where performance might matter.
Now that Go includes slice operations such as slices.Contains, some uses of sets are no longer useful. In particular, creating a set using a slice just to check whether the slice contains a specific item is more expensive than checking the slice directly. Signed-off-by: Stephen Kitt <skitt@redhat.com>
/lgtm |
/approve |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: deads2k, dusk125, skitt The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@skitt: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Now that Go includes slice operations such as slices.Contains, some uses of sets are no longer useful. In particular, creating a set using a slice just to check whether the slice contains a specific item is more expensive than checking the slice directly.